<template>
  <div>
    <el-card shadow="never" style="margin:30px">
      <div slot="header">
        <span>条件查询</span>
      </div>
      <el-form ref="form" size="mini" :model="orderList" label-width="80px" :inline="false">
        <el-row :gutter="20">
          <el-col :span="8" :offset="0">
            <el-form-item label="订单编号">
              <el-input v-model="orderList.orderSn " placeholder="请填写订单编号" />
            </el-form-item>
          </el-col>
          <el-col :span="8" :offset="0">
            <el-form-item label="退单状态">
              <el-select v-model="orderList.status " placeholder="退单状态">
                <el-option
                  v-for="item in paystatus"
                  :key="item.id"
                  :label="item.mode"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12" :offset="18">
            <el-form-item>
              <el-button type="primary" size="mini" style="margin-right:10px" @click="onSubmit">搜索</el-button>
              <el-button size="mini" @click="reset">重置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <el-card shadow="never" class="bigCard">
      <el-table :data="backList" border stripe>
        <el-table-column
          type="index"
          label="#"
          :width="70"
          fixed
          align="center"
        />

        <el-table-column
          prop="orderSn"
          label="订单编号"
          :width="200"
          align="center"
        />
        <el-table-column
          label="退单状态"
          align="center"
          :width="180"
        >
          <template slot-scope="scope">
            <button v-if="scope.row.status === 0" class="status" style="background-color:#f56c6c">待处理</button>
            <button v-if="scope.row.status === 1" class="status" style="background-color:#e6a23c">退货中</button>
            <button v-if="scope.row.status === 2" class="status" style="color: #409eff;background-color:#d9ecff">已完成</button>
            <button v-if="scope.row.status === 3" class="status" style="background-color:#409eff">已拒绝</button>
          </template>
        </el-table-column>
        <el-table-column
          label="描述"
          :width="150"
          align="center"
        >
          <template slot-scope="scope">
            <p>{{ scope.row.description }}</p>
          </template>
        </el-table-column>
        <el-table-column
          label="退单原因"
          align="center"
          :width="180"
        >
          <template slot-scope="scope">
            <p>{{ scope.row.reason }}</p>
          </template>
        </el-table-column>
        <el-table-column
          prop="productName"
          label="商品名称"
          align="center"
          :width="150"
        />
        <el-table-column
          align="center"
          label="商品属性"
          :width="200"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.productAttr[0].key }}</span>: <span>{{ scope.row.productAttr[0].value }}</span><br>
            <span>{{ scope.row.productAttr[1].key }}</span>: <span>{{ scope.row.productAttr[1].value }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="handleNote"
          label="备注"
          align="center"
          :width="100"
        />
        <el-table-column
          prop="createTime"
          label="添加时间"
          align="center"
          :width="200"
        />
        <el-table-column
          label="操作"
          align="center"
          :width="200"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button type="primary" style="width:120px" size="mini" @click="viewOrder(scope.row.id)">查看订单</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        style="margin-top:20px; text-align:right"
        :current-page="articleObj.start"
        :page-sizes="articleObj.sizes"
        :page-size="articleObj.limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="articleObj.totalCount"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>
  </div>
</template>

<script>
import mixin from '@/mixins'
import { findReturnApply } from '@/api/order/chargeBack'
export default {
  mixins: [mixin],
  data() {
    return {
      orderList: {}, // 搜索条件
      backList: [], // 退单列表
      paystatus: [ // 支付方式
        {
          mode: '待处理',
          id: 0
        },
        {
          mode: '退货中',
          id: 1
        },
        {
          mode: '已完成',
          id: 2
        },
        {
          mode: '已拒绝',
          id: 3
        }
      ]
    }
  },
  computed: {

  },
  created() {
    this.init()
  },
  mounted() {

  },
  methods: {
    init() {
      findReturnApply(this.articleObj.start, this.articleObj.limit, this.orderList).then(res => {
        const { message: errMag, data, success } = res
        if (success) {
          const { rows, total } = data
          console.log(rows)
          rows.forEach(element => {
            element.productAttr = JSON.parse(element.productAttr)
          })
          this.backList = rows
          console.log(this.backList)

          this.articleObj.totalCount = total
        } else {
          this.$message.error(errMag)
        }
      })
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`)
      this.articleObj.limit = val
      this.init()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`)
      this.articleObj.start = val
      this.init()
    },
    onSubmit() { // 搜索
      this.articleObj.start = 1
      this.init()
    },
    reset() { // 重置
      this.orderList = {}
      this.init()
    },
    viewOrder(id) { // 查看订单
      this.$router.push({ name: 'OrderBack', params: { id: id }})
    }
  }
}
</script>

<style scoped lang="scss">
  .bigCard{
        margin: 30px;
        margin-top:0px;
    }
    .status{
        width: 60px;
        height: 30px;
        color:aliceblue;
        border: none;
        border-radius: 10%;
        font-size: 12px;
        font-family: YaHei;
        background-color: #888888;
    }
    .statu{
      width: 60px;
      height: 30px;
      background-color: #f0f9eb;
      border-color: #e1f3d8;
      color: #67c23a;
       border: none;
        border-radius: 10%;
        font-size: 12px;
        font-family: YaHei;
    }
</style>
